<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>JS设置DES加密处理</title>
<script type="text/javascript" src="${base}/js/jquery.min.js"></script>
<script src="${base}/js/crytojs/rollups/tripledes.js"></script>
<script src="${base}/js/crytojs/components/mode-ecb.js"></script>

<script type="text/javascript">
	var key = '1234567812345678';
	
	//DES  ECB模式加密
	function encryptByECB(message) {
		var keyHex = CryptoJS.enc.Utf8.parse(key);
		var content = CryptoJS.enc.Utf8.parse(message)
		var encrypted = CryptoJS.DES.encrypt(content, keyHex, {
			mode : CryptoJS.mode.ECB,
			padding : CryptoJS.pad.Pkcs7
		});
		return encrypted.ciphertext.toString();
	}

	//DES  ECB模式解密
	function decryptByECB(ciphertext) {
		var keyHex = CryptoJS.enc.Utf8.parse(key);
		var decrypted = CryptoJS.DES.decrypt({
			ciphertext : CryptoJS.enc.Hex.parse(ciphertext)
		}, keyHex, {
			mode : CryptoJS.mode.ECB,
			padding : CryptoJS.pad.Pkcs7
		});
		var result_value = decrypted.toString(CryptoJS.enc.Utf8);
		return result_value;
	}
	
	
	
	function test() {
		var source = $("#source").val();
		var cc = encryptByECB(source);
		$("#target").val(cc);
	}

	function test1() {
		var source = $("#sourceS").val();
		var dd = decryptByECB(source);
		$("#jiemi").val(dd);
	}
	
	function decodeStr(){
		var keyword = encryptByECB("https://www.baidu.com/+=", key);
		window.open("${base}/crytoDes/decode?keyword="+keyword);
	}
</script>
</head>
<body>
	<div>
		原文:<textarea id="source" value="" style="width: 500px; height: 90px;" /></textarea>
		<hr>
		密文:<textarea id="target" value="" style="width: 500px; height: 90px;"></textarea>
		<hr>
		<input type="button" onclick="test();" name="" value="加密" />
		<hr>
		密文: <textarea id="sourceS" value="" style="width: 500px; height: 90px;"></textarea>
		<hr>
		原文: <textarea id="jiemi" value="" style="width: 500px; height: 90px;"></textarea>
		<hr>
		<input type="button" onclick="test1();" name="" value="解密" />
		<hr>
		<input  type="button"   onclick="decodeStr()"  value="后端解密">
	</div>
</body>
</html>